package com.sunny.shop.util;

import com.sunny.shop.bo.PageCounter;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

public class CommonUtil {
    public static PageCounter converToParameter(Integer start, Integer count){
        int pageNum = start / count;
        PageCounter build = PageCounter.builder().page(pageNum).count(count).build();
        return build;
    }

    /**
     * 生成订单号
     * @return
     */
    public static String createOrderSn(){
        SimpleDateFormat dmDate = new SimpleDateFormat("yyyyMMddHHmmss"); // 获取当前时间

        Random random = new Random(); // 定义随机数
        int ran = random.nextInt(1000000); // 随机数长度位数

        Date date = new Date();
        String dateran = dmDate.format(date);
        String orderSn = dateran+ran;
        return orderSn;
    }

    public static String getSimpleData(Date dateTime){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return simpleDateFormat.format(dateTime);
    }
}
